/**
  ******************************************************************************
  * @file    Bsp/Weight.h 
  * @author  zlf
  * @version V1.0.0
  * @date    2016-08-08
  * @brief   Header for Weight.c module
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef    __WEIGHT_H
#define    __WEIGHT_H

/* Includes ------------------------------------------------------------------*/
	#include "main.h"

/* Exported types ------------------------------------------------------------*/
typedef  struct{
	void (* init)(void);
	void (* samp)(void);
	bool (* lost)(void);
}F_WEIGHT_Typedef;

/* Exported constants --------------------------------------------------------*/
#define LOSTLOAD 	 	( tSet[TS_WEIGHT0] - ( tSet[TS_LOADCALIB] * tSet[TS_LOADLOST]  ) / 10 ) // 3kg / 100 
#define OVERLOAD  		( ( tSet[TS_LOADCALIB]  * tSet[TS_OVERLOAD])/10 + tSet[TS_WEIGHT0] ) // 200 kg
#define MAXLOAD  		( ( tGlobal.MaxWeight  * tSet[TS_LOADCALIB])/10 + tSet[TS_WIRELOOSEN] ) 

#define  WEIGHT_FLOAT_TIMER  (300)
#define  WEIGHT_REDUCE_SINGLE_TIMER  (10)
#define  WEIGHT_VALID_KG (20)


/* Exported constants --------------------------------------------------------*/

#define WEIGHT_GPIO  	  	( GPIOF )
#define WEIGHT_CLK_PIN 		( GPIO_Pin_0 ) 
#define WEIGHT_DATA_PIN 	( GPIO_Pin_1 ) 
#define WEIGHT_CS_PIN 		( GPIO_Pin_2 ) 

/* Exported macro ------------------------------------------------------------*/

#define WEIGHT_CS_0			( GPIO_ResetBits(WEIGHT_GPIO, WEIGHT_CS_PIN) )
#define WEIGHT_CS_1			( GPIO_SetBits(WEIGHT_GPIO, WEIGHT_CS_PIN) )
			
#define WEIGHT_CLK_0		( GPIO_ResetBits(WEIGHT_GPIO, WEIGHT_CLK_PIN) )
#define WEIGHT_CLK_1		( GPIO_SetBits(WEIGHT_GPIO, WEIGHT_CLK_PIN) )

#define WEIGHT_DATA_IN 		( GPIO_ReadInputDataBit(WEIGHT_GPIO, WEIGHT_DATA_PIN) )

/* Exported varables --------------------------------------------------------*/
extern F_WEIGHT_Typedef fWeight;

#endif /* __WEIGHT_H */
 
 
